package com.ywl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ywl.mapper.ClazzMapper;
import com.ywl.pojo.Clazz;
import com.ywl.pojo.Grade;
import com.ywl.service.ClazzService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.thymeleaf.util.StringUtils;

import java.util.List;

/**
 * @author DL5O
 * @version 1.0
 */

@Service("clazzServiceImpl")
@Transactional
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz> implements ClazzService {

    /**
     * 分页查询
     * @param pageParam
     * @param clazz
     * @return
     */
    @Override
    public IPage<Clazz> getClazzOpr(Page<Clazz> pageParam, Clazz clazz) {
        QueryWrapper<Clazz> queryWrapper = new QueryWrapper<>();
        String gradeName = clazz.getGradeName();//年级名
        String name = clazz.getName();

        if (!StringUtils.isEmpty(gradeName)) {
            queryWrapper.like("grade_name",gradeName);//查找包含关键字的名称
        }
        if(!StringUtils.isEmpty(name)){
            queryWrapper.like("name",name);
        }

        Page<Clazz> clazzPage = baseMapper.selectPage(pageParam, queryWrapper);//第几页，也大小
        return clazzPage;
    }

    /**
     * 查询年级信息
     * @return
     */
    @Override
    public List<Clazz> getClazzs() {
        return baseMapper.selectList(null);
    }

}
